/*
 * @brief
 * @author li yong (DogLee)
 * @email 20162439@qq.com
 * @version 1.0
 * @date 2018-08-03 10:43:20
 */
#include "logappenderterminal.h"

LogAppenderTerminal::LogAppenderTerminal() : ILogAppender()
{

}

LogAppenderTerminal::~LogAppenderTerminal()
{

}

void LogAppenderTerminal::append(const DebugMessage &message)
{
    if (message.content.contains("Could not read from input device (No such device)"))
        return;

    switch (message.type)
    {
        default:
        case QtDebugMsg:
            {
                SETCOLOR(37);
                printf("%s[D]", message.time.toLocal8Bit().constData());
                printf("%s -> ", message.context.toLocal8Bit().constData());
                SETCOLOR(39);
                printf("%s\r\n", message.content.toLocal8Bit().constData());
                RESETCOLOR();
            }
            break;
        case QtWarningMsg:
            {
                SETCOLOR(37);
                printf("%s[W]", message.time.toLocal8Bit().constData());
                printf("%s -> ", message.context.toLocal8Bit().constData());
                SETCOLOR(33);
                printf("%s\r\n", message.content.toLocal8Bit().constData());
                RESETCOLOR();
            }
            break;
        case QtCriticalMsg:
            {
                SETCOLOR(37);
                printf("%s[C]", message.time.toLocal8Bit().constData());
                printf("%s -> ", message.context.toLocal8Bit().constData());
                SETCOLOR(31);
                printf("%s\r\n", message.content.toLocal8Bit().constData());
                RESETCOLOR();
            }
            break;
        case QtFatalMsg:
            {
                SETCOLOR(37);
                printf("%s[F]", message.time.toLocal8Bit().constData());
                printf("%s -> ", message.context.toLocal8Bit().constData());
                SETCOLOR(31);
                printf("%s\r\n", message.content.toLocal8Bit().constData());
                RESETCOLOR();
            }
            break;
        case QtInfoMsg:
            {
                SETCOLOR(37);
                printf("%s[I]", message.time.toLocal8Bit().constData());
                printf("%s -> ", message.context.toLocal8Bit().constData());
                SETCOLOR(32);
                printf("%s\r\n", message.content.toLocal8Bit().constData());
                RESETCOLOR();
            }
            break;
    }

    fflush(stdout);
}
